<template>
	<div class="login_bg">
		<div class="login_adv">
			<div class="login_adv__title">
				<img class="logo" src="img/logo.png" alt="">
				<span class="sys-title">管理系统</span>
			</div>
		</div>
		<div class="login_main">
			<div class="login-form">
				<div class="login-header">
					Please Sign in
				</div>
				<el-tabs>
					<el-tab-pane :label="$t('login.accountLogin')" lazy>
						<password-form></password-form>
					</el-tab-pane>
					<el-tab-pane :label="$t('login.mobileLogin')" lazy>
						<phone-form></phone-form>
					</el-tab-pane>
				</el-tabs>
				<template v-if="$CONFIG.MY_SHOW_LOGIN_OAUTH">
					<el-divider>{{ $t('login.signInOther') }}</el-divider>
					<div class="login-oauth">
						<el-button type="success" icon="sc-icon-wechat" circle @click="wechatLogin"></el-button>
					</div>
				</template>
			</div>
		</div>
		<Copyright />
	</div>
	<el-dialog v-model="showWechatLogin" :title="$t('login.wechatLoginTitle')" :width="400" destroy-on-close>
		<div class="qrCodeLogin">
			<sc-qr-code class="qrCode" :text="WechatLoginCode" :size="200"></sc-qr-code>
			<p class="msg">{{ $tc('login.wechatLoginMsg', 1) }}<br />{{ $tc('login.wechatLoginMsg', 2) }}</p>
			<div class="qrCodeLogin-result" v-if="isWechatLoginResult">
				<el-result icon="success" :title="$tc('login.wechatLoginResult', 1)"
					:sub-title="$tc('login.wechatLoginResult', 2)"></el-result>
			</div>
		</div>
	</el-dialog>
</template>

<script>
import Copyright from './Copyright';
import passwordForm from './components/passwordForm'
import phoneForm from './components/phoneForm'

export default {
	components: {
		passwordForm,
		phoneForm,
		Copyright
	},
	data() {
		return {
			config: {
				lang: this.$TOOL.data.get('APP_LANG') || this.$CONFIG.LANG,
				dark: this.$TOOL.data.get('APP_DARK') || false
			},
			lang: [
				{
					name: '简体中文',
					value: 'zh-cn',
				},
				{
					name: 'English',
					value: 'en',
				}
			],
			WechatLoginCode: "",
			showWechatLogin: false,
			isWechatLoginResult: false
		}
	},
	watch: {
		'config.dark'(val) {
			if (val) {
				document.documentElement.classList.add("dark")
				this.$TOOL.data.set("APP_DARK", val)
			} else {
				document.documentElement.classList.remove("dark")
				this.$TOOL.data.remove("APP_DARK")
			}
		},
		'config.lang'(val) {
			this.$i18n.locale = val
			this.$TOOL.data.set("APP_LANG", val)
		}
	},
	created: function () {
		console.log();
		for (const key in window.localStorage) {
			if (Object.prototype.hasOwnProperty.call(window.localStorage, key)) {
				if (key.indexOf("MENU")) {
					window.localStorage.removeItem(key)
				}
			}
		}
		this.$TOOL.cookie.remove("TOKEN")
		this.$TOOL.data.remove("USER_INFO")
		this.$TOOL.data.remove("MENU")
		this.$TOOL.data.remove("PERMISSIONS")
		this.$TOOL.data.remove("DASHBOARDGRID")
		this.$TOOL.data.remove("grid")
		this.$store.commit("clearViewTags")
		this.$store.commit("clearKeepLive")
		this.$store.commit("clearIframeList")
		console.log('%c SCUI %c Gitee: https://gitee.com/lolicode/scui', 'background:#666;color:#fff;border-radius:3px;', '')
	},
	methods: {
		configDark() {
			this.config.dark = this.config.dark ? false : true
		},
		configLang(command) {
			this.config.lang = command.value
		},
		wechatLogin() {
			this.showWechatLogin = true
			this.WechatLoginCode = "SCUI-823677237287236-" + new Date().getTime()
			this.isWechatLoginResult = false
			setTimeout(() => {
				this.isWechatLoginResult = true
			}, 3000)
		}
	}
}
</script>

<style lang="scss" scoped>
.login_bg {
	height: 100%;
	width: 100%;
	overflow: hidden;
	display: flex;
	align-items: center;
	justify-content: center;
	background-color: #ffffff;
	border-radius: 0px 0px 0px 0px;
	background-image: url('@/assets/images/login-page-bg.png');
	background-position: center center;
	background-repeat: no-repeat;
	background-attachment: fixed;
	background-size: cover;
	user-select: none;
}

.login_adv {
	width: 490px;
	height: 550px;
	background-image: url('@/assets/images/login-bg.png');
	background-color: #ffffff;
	background-size: cover;
	background-position: center center;
	background-repeat: no-repeat;
	position: relative;
	box-shadow: 0px 0px 20px 0px rgba(196, 193, 219, 0.2);
}

.login_adv__title {
	display: flex;
	align-items: center;
	padding: 40px;

	.logo {
		width: 40px;
		height: 40px;
	}

	.sys-title {
		font-size: 20px;
		font-family: Source Han Sans CN-Medium, Source Han Sans CN;
		font-weight: 600;
		color: #FFFFFF;
		margin-left: 8px;
	}
}

.login_main {
	width: 510px;
	height: 550px;
	background-color: #ffffff;
	box-shadow: 0px 0px 20px 0px rgba(196, 193, 219, 0.2);
}

.login-form {
	width: 346px;
	margin: auto;
	padding: 34px 0 0;
}

.login-header {
	margin-bottom: 10px;
	height: 44px;
	font-size: 30px;
	font-family: Source Han Sans CN-Medium, Source Han Sans CN;
	font-weight: 600;
	color: #4066F1;
	letter-spacing: 1px;
}

.login-oauth {
	display: flex;
	justify-content: space-around;
}

.login-form .el-divider {
	margin-top: 40px;
}

.login-form {}

.login-form:deep(.el-tabs) .el-tabs__header {
	margin-bottom: 25px;
}

.login-form:deep(.el-tabs) .el-tabs__header .el-tabs__item {
	font-size: 14px;
}

.login-form:deep(.login-forgot) {
	text-align: right;
}

.login-form:deep(.login-forgot) a {
	color: var(--el-color-primary);
}

.login-form:deep(.login-forgot) a:hover {
	color: var(--el-color-primary-light-3);
}

.login-form:deep(.login-reg) {
	font-size: 14px;
	color: var(--el-text-color-primary);
}

.login-form:deep(.login-reg) a {
	color: var(--el-color-primary);
}

.login-form:deep(.login-reg) a:hover {
	color: var(--el-color-primary-light-3);
}

.login_config {
	position: absolute;
	top: 20px;
	right: 20px;
}

.login-form:deep(.login-msg-yzm) {
	display: flex;
	width: 100%;
}

.login-form:deep(.login-msg-yzm) .el-button {
	margin-left: 10px;
	--el-button-size: 42px;
}

.qrCodeLogin {
	text-align: center;
	position: relative;
	padding: 20px 0;
}

.qrCodeLogin img.qrCode {
	background: #fff;
	padding: 20px;
	border-radius: 10px;
}

.qrCodeLogin p.msg {
	margin-top: 15px;
}

.qrCodeLogin .qrCodeLogin-result {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	text-align: center;
	background: var(--el-mask-color);
}

@media (max-width: 1200px) {
	.login-form {
		width: 340px;
	}
}

@media (max-width: 1000px) {
	.login_main {
		display: block;
	}

	.login_main .login_config {
		position: static;
		padding: 20px 20px 0 20px;
		text-align: right;
	}

	.login-form {
		width: 100%;
		padding: 20px 40px;
	}

	.login_adv {
		display: none;
	}
}
</style>
